lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

index.md (1649B)


      1 +++
      2 title = 'Program-controlled I/O'
      3 +++
      4 # Program-controlled I/O
      5 “a program that performs all functions needed to realise the desired action”
      6 
      7 difference in speed between processor and I/O devices, need to synchronise transfer of data
      8 
      9 solution — signalling protocol (wait for signal from device, a status flag)
     10 
     11 polling — checking the device’s status flag
     12 
     13 ## Example: RISC-style I/O
     14 reads from keyboard, echoes back to display. end on newline
     15 
     16 1. Point register R2 to address of first location in main memory where read characters will be stored
     17 
     18 2. Load newline character (terminator) into R3
     19 3. Start input loop
     20     1. Move keyboard status into R4
     21     2. R4 = R4 AND #2
     22         - the KIN status flag is the second byte of the value in R4 — so R4 looks like `...0X` or `...1X`
     23         - #2 is 10 in binary
     24         - ANDing them together gives you the state of the KIN flag (i.e. 0X AND 10 = 0X)
     25 
     26     3. If [R4] is 0 (KIN is false), jump to step 1 of loop
     27 4. Load `KBD_DATA` byte into R5 (clearing KIN to 0)
     28 5. Store R5 into address in R2
     29 6. Increment pointer in R2 (to store next character)
     30 7. Start output loop
     31     1. Load `DISP_STATUS` byte into R4
     32     2. R4 = R4 AND #2
     33 
     34         - the DOUT flag is the third byte of the value in R4 — so R4 is either …0XX or …1XX
     35         - #4 is 100 in binary
     36         - ANDing them together gives you the state of the DOUT flag (i.e. 0XX AND 100 = 0XX)
     37 
     38     3. If [R4] is 0, jump to step 1 of loop
     39 8. Store byte in R5 into `DISP_DATA`
     40 9. If the Terminator isn’t in R5 ([R5] ≠ [R3]), jump to step 3 (input loop)
     41 
     42 ![screenshot.png](screenshot-21.png)
     43 
     44 ![screenshot.png](screenshot-20.png)